package com.fang.system.netty.handler;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

/**
 * @author fanglingxiao
 * @version 1.0
 * @description TODO
 * @date 2022/7/15 9:06 下午
 **/
@ChannelHandler.Sharable
public abstract class ChannelInitHandler extends ChannelInboundHandlerAdapter {

    protected abstract void init(SocketChannel client);

    @Override
    public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
        SocketChannel client = (SocketChannel) ctx.channel();
        this.init(client);
        ChannelPipeline pipeline = client.pipeline();
        pipeline.remove(this);
    }
}
